package com.tairanchina.wiki.api.model.wiki.navigation;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 周靖捷 on 2016/10/1.
 */
public class ProjectNavigation implements NavigationElement {
    String title;
    List<NavigationElement> navigationItems;

    public String getTitle() {
        return title;
    }

    public ProjectNavigation setTitle(String title) {
        this.title = title;
        return this;
    }

    public List<NavigationElement> getNavigationItems() {
        return navigationItems;
    }

    public ProjectNavigation setNavigationItems(List<NavigationElement> navigationItems) {
        this.navigationItems = navigationItems;
        return this;
    }

    public ProjectNavigation addNavigationItems(NavigationElement item) {
        if (navigationItems == null) {
            navigationItems = new ArrayList<NavigationElement>();
        }
        navigationItems.add(item);
        return this;
    }

    @Override
    public String toMarkdown() {
        StringBuffer sb = new StringBuffer();
        sb.append("# ").append(title == null ? "" : title);
        sb.append(System.lineSeparator());
        if (navigationItems != null)
            for (NavigationElement item : navigationItems) {
                sb.append(System.lineSeparator());
                sb.append(item.toMarkdown());
            }
        return sb.toString();
    }
}
